﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Leikjavefurinn.Repo;
using Leikjavefurinn.Context;

namespace Leikjavefurinn.Controllers
{
    public class HomeController : Controller
    {
        private ITicTacToeRepo _repository = null;

        //smiður sem býr til tilvik af TicTacToe repo
        public HomeController()
        {
            _repository = new TicTacToeRepo();
        }

        public HomeController(ITicTacToeRepo rep)
        {
            _repository = rep;
        }

        //Fall sem skilar lista af öllum Active Tic Tac Toe leikjum í Index-ið
        public ActionResult Index()
        {
            IEnumerable<TicTacToeGame> Games = (from tick in _repository.AllTickTacToe()
                                                join game in _repository.AllGames()
                                                on tick.GameId equals game.GameId
                                                where game.IsActive == true
                                                select tick);
            return View(Games);
        }
    }
}
